package com.example.proxy2;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

//通用的CglibProxy创建工厂
public class CglibProxyFactory {
    //该方法能为所有类创建代理
    public static Object createProxy(Class targetClass, MethodInterceptor proxy) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(targetClass);
        enhancer.setCallback(proxy);
        return enhancer.create();
    }
}
